<html>
<head>
<script type="text/javascript">
//<![CDATA[[
	
	
	function initTable() {
		var tbl = document.getElementById("tbl");
		
		var tbl = document.getElementById("tbl");
		for (var i=0; i<3; i++) {
			//addRow();
			
			//alert(tbl.rows.length);
			
			var newTr = document.createElement("tr");
			newTr.clickedRowIndex = i;
			var td1 = document.createElement("td");
			td1.innerHTML = "td1";
			var td2 = document.createElement("td");
			td2.innerHTML = "td2";
			var td3 = document.createElement("td");
			td3.innerHTML = "td3";
			var btn = document.createElement("button");
			//btn.addEventListener("onClick", delRow(), false);
	        btn.attachEvent('onclick', delRow);
	        
			td3.appendChild(btn);
			
			newTr.appendChild(td1);
			newTr.appendChild(td2);
			newTr.appendChild(td3);
			
			tbl.firstChild.appendChild(newTr);
			
		}
	}
	
	function test1() {
		var divTest = document.getElementById("divTest");
		divTest.innerHTML = "test";
	}
	
	function test2() {
		var body = document.getElementsByTagName("body")[0];
		var newDiv = document.createElement("div");
		newDiv.innerHTML = "new div";
		body.appendChild(newDiv);
	}
	
	function addRow() {
		var tbl = document.getElementById("tbl");
		//alert(tbl.rows.length);
		
		var newTr = document.createElement("tr");
		//newTr.clickedRowIndex = idx;
		var td1 = document.createElement("td");
		td1.innerHTML = "td1";
		var td2 = document.createElement("td");
		td2.innerHTML = "td2";
		var td3 = document.createElement("td");
		td3.innerHTML = "td3";
		var btn = document.createElement("button");
		//btn.addEventListener("onClick", delRow(), false);
        btn.attachEvent('onclick', delRow);
		td3.appendChild(btn);
		
		newTr.appendChild(td1);
		newTr.appendChild(td2);
		newTr.appendChild(td3);
		
		tbl.firstChild.appendChild(newTr);
	}
	
	function delRow() {
		//alert(a.parent);
		//var rowToDel = document.
		var tbl = document.getElementById("tbl");
		var rowToDelIdx = tbl.clickedRowIndex;
		alert(tbl.clickedRowIndex);
		//tbl.deleteRow(1);
		//this.removeElement(this);
		//tbl.removeChild(tr);
	}
	
//]]>
</script>
</head>
<body>
	<div id="divTest">div test</div>

	<table id="tbl">
		
	</table>
	

	<input type="button" value="test1" onClick="test1()" />
	<input type="button" value="test2" onClick="test2()" />
	<input type="button" value="btn" onClick="initTable()" />
	<input type="button" value="btn" onClick="addRow()" />
	
</body>
</html>